package com.hyt.it.ogt.kq.main.controller.admission;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.exception.annotation.ThrowsAdvice;
import com.hyt.it.ogt.kq.common.gov.config.swagger.ApiVersionConstant;
import com.hyt.it.ogt.kq.common.gov.constant.ResponseCode;
import com.hyt.it.ogt.kq.service.admission.IExamineeInfoService;
import com.hyt.it.ogt.kq.service.gov.model.param.admission.ExamineeInfoPageParam;
import com.hyt.it.ogt.kq.service.gov.model.vo.admission.ExamineeInfoPageVO;
import com.hyt.it.ogt.kq.common.gov.progress.ImportAdmissionTicketPhotoLockKeyCreator;
import com.hyt.it.ogt.kq.main.controller.base.BaseController;
import com.hyt.log.annotation.Log;
import com.hyt.progress.creator.anno.ProgressAnno;
import com.hyt.swagger.ApiVersion;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 准考证考生信息 前端控制器
 * </p>
 *
 * @author yanghuankun@talkweb.com.cn
 * @since 2023-1-13
 */
@RestController
@Api(tags = "233.准考证考生信息接口", value = "准考证考生信息接口")
@ApiSort(value = 233)
@RequestMapping("/kw/gov/admission/ticket/examinee")
@Slf4j
public class ExamineeInfoController extends BaseController {

    @Resource
    IExamineeInfoService examineeInfoService;

    @ApiOperation(
            value = "33.1 考生分页列表接口",
            notes = "30000:成功;43140101:获取考生分页数据异常",
            response = ExamineeInfoPageVO.class
    )
    @ApiOperationSort(value = 1)
    @ApiVersion(group = ApiVersionConstant.V2_4_6)
    @Log(module = "准考证考生信息管理", business = "考生分页列表接口")
    @ThrowsAdvice(code = 43140101, print = "获取考生分页数据异常")
    @PostMapping("/page")
    public ApiResponse<IPage<ExamineeInfoPageVO>> pageExamineeInfo(@RequestBody @Validated ExamineeInfoPageParam<?> examineeInfoPageParam,
                                                                   BindingResult bindingResult) {
        this.checkValid(bindingResult);
        return ApiResponse.<IPage<ExamineeInfoPageVO>>builder()
                .code(ResponseCode.SUCCESS.getCode())
                .data(examineeInfoService.pageExamineeInfo(examineeInfoPageParam))
                .build();
    }

    @ApiOperation(
            value = "33.2 取消生成准考证",
            notes = "30000:成功;43330201:取消生成准考证失败",
            response = Boolean.class
    )
    @ApiOperationSort(value = 2)
    @ApiVersion(group = ApiVersionConstant.V2_4_6)
    @Log(module = "准考证考生信息管理", business = "取消生成准考证")
    @ThrowsAdvice(code = 43330201, print = "取消生成准考证失败")
    @GetMapping("/cancelGenerate")
    public ApiResponse<Boolean> cancelGenerate(@ApiParam("准考证考生ID") @RequestParam String examineeInfoId) {
        return ApiResponse.<Boolean>builder()
                .code(ResponseCode.SUCCESS.getCode())
                .data(examineeInfoService.cancelGenerate(examineeInfoId))
                .build();
    }

    @ApiOperation(
            value = "33.3 批量取消生成准考证",
            notes = "30000:成功;43330301:批量取消生成准考证失败",
            response = Boolean.class
    )
    @ApiOperationSort(value = 3)
    @ApiVersion(group = ApiVersionConstant.V2_4_6)
    @Log(module = "准考证考生信息管理", business = "批量取消生成准考证")
    @ThrowsAdvice(code = 43330301, print = "批量取消生成准考证失败")
    @GetMapping("/batchCancelGenerate")
    public ApiResponse<Boolean> batchCancelGenerate(@ApiParam("准考证ID") @RequestParam String admissionTicketInfoId) {
        return ApiResponse.<Boolean>builder()
                .code(ResponseCode.SUCCESS.getCode())
                .data(examineeInfoService.batchCancelGenerate(admissionTicketInfoId))
                .build();
    }

    @ApiOperation(
            value = "33.4 导入考生证件照片",
            notes = "20000:成功;"
    )
    @ApiOperationSort(value = 4)
    @ApiVersion(group = ApiVersionConstant.V2_4_6)
    @Log(module = "准考证考生信息管理", business = "导入考生证件照片")
    @ProgressAnno(total = 100, timeoutSeconds = 60 * 60 * 5, errorCode = 43330401, canConcurrent = false, lockKeyCreator = ImportAdmissionTicketPhotoLockKeyCreator.class)
    @PostMapping("/importAdmissionTicketPhoto")
    public void importAdmissionTicketPhoto(@ApiParam(value = "导入数据文件URL") @RequestParam String zipFileUrl,
                                           @ApiParam(value = "准考证ID") @RequestParam String admissionTicketInfoId) {
        examineeInfoService.importAdmissionTicketPhoto(zipFileUrl, admissionTicketInfoId);
    }

    @ApiOperation(
            value = "33.5 生成准考证",
            notes = "20000:成功;",
            response = Boolean.class
    )
    @ApiOperationSort(value = 5)
    @ApiVersion(group = ApiVersionConstant.V2_4_6)
    @Log(module = "准考证考生信息管理", business = "生成准考证")
    @ThrowsAdvice(code = 43330501, print = "生成考生准考证失败")
    @GetMapping("/generateAdmissionTicket")
    public ApiResponse<Boolean> generateAdmissionTicket(@ApiParam(value = "考生ID") @RequestParam String examineeInfoId) {
        return ApiResponse.<Boolean>builder()
                .code(ResponseCode.SUCCESS.getCode())
                .data(examineeInfoService.generateAdmissionTicket(examineeInfoId))
                .build();
    }

    @ApiOperation(
            value = "33.6 预览准考证",
            notes = "20000:成功;",
            response = Boolean.class
    )
    @ApiOperationSort(value = 6)
    @ApiVersion(group = ApiVersionConstant.V2_4_6)
    @Log(module = "准考证考生信息管理", business = "预览准考证")
    @ThrowsAdvice(code = 43330601, print = "预览准考证失败")
    @GetMapping("/preview")
    public ApiResponse<String> preview(@ApiParam(value = "考生ID") @RequestParam String examineeInfoId) {
        return ApiResponse.<String>builder()
                .code(ResponseCode.SUCCESS.getCode())
                .data(examineeInfoService.preview(examineeInfoId))
                .build();
    }
}
